package entity;

import sportmgr.common.Common;
import sportmgr.service.BallService;
import sportmgr.service.WaterService;

/**
 * 羽毛球套餐
 *
 * @author
 *
 */
public class BallPackage extends ServicePackage
        implements BallService, WaterService {
    private int ballTime; // 羽毛球时间（小时）
    private int waterNum; // 饮用矿泉水数量（瓶）

    public BallPackage() {
        //套餐数据初始化
        this.ballTime = 20;
        this.waterNum = 10;
        this.price = 80.0;
    }

    public BallPackage(int ballTime,int waterNum) {
        super();
        this.ballTime = ballTime;
        this.waterNum = waterNum;
    }

    @Override
    public void showInfo() {
        System.out.println("羽毛球套餐：羽毛球时间是" + this.ballTime
                + "小时/月,矿泉水数为"
                + this.waterNum + "瓶/月，资费为"
                + this.price + "元/月。");
    }

    @Override
    public int ballPlay(int ball, VipCard card) throws Exception {
        int temp = waterNum;
        for(int i=0;i<waterNum;i++){
            if(this.waterNum-card.getRealWaterNum()>=1){
                //第一种情况：套餐剩余矿泉水可以支持提供1瓶矿泉水
                card.setRealWaterNum(card.getRealWaterNum()+1); //实际饮用矿泉水加1
            }else if(card.getMoney()>=3){
                //第二种情况:套餐免费矿泉水数已用完，账户余额可以支付1瓶矿泉水，使用账户余额支付
                card.setRealWaterNum(card.getRealWaterNum()+1);
                card.setMoney(Common.sub(card.getMoney(),3)); //账户余额消费3元（1瓶矿泉水费用）
                card.setConsumAmount(card.getConsumAmount() + 3);
            }else{
                temp = i;
                throw new Exception("本次已饮用矿泉水"+i+"瓶,您的余额不足，请充值后再使用！");
            }
        }
        return temp;
    }

    public int getBallTime() {
        return ballTime;
    }

    public void setBallTime(int ballTime) {
        this.ballTime = ballTime;
    }

    public int getWaterNum() {
        return waterNum;
    }

    public void setWaterNum(int waterNum) {
        this.waterNum = waterNum;
    }

    @Override
    public int water(int waterNum, VipCard card) throws Exception {
        int temp = waterNum;
        for(int i=0;i<waterNum;i++){
            if(this.waterNum-card.getRealWaterNum()>=1){
                //第一种情况：套餐剩余矿泉水可以支持提供1瓶矿泉水
                card.setRealWaterNum(card.getRealWaterNum()+1); //实际饮用矿泉水加1
            }else if(card.getMoney()>=3){
                //第二种情况:套餐免费矿泉水数已用完，账户余额可以支付1瓶矿泉水，使用账户余额支付
                card.setRealWaterNum(card.getRealWaterNum()+1);
                card.setMoney(Common.sub(card.getMoney(),3)); //账户余额消费3元（1瓶矿泉水费用）
                card.setConsumAmount(card.getConsumAmount() + 3);
            }else{
                temp = i;
                throw new Exception("本次已饮用矿泉水"+i+"瓶,您的余额不足，请充值后再使用！");
            }
        }
        return temp;
    }
}